package org.example.struct.array;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author liyishan
 * @date 2023/8/2 10:27
 * @apiNote
 */

public class Test00448FindDisappearedNumbers {
    public static void main(String[] args) {
        int[] a = new int[]{1, 1,2,2,4};
        List<Integer> result= test(a);
        System.out.println("  array:" + JSON.toJSON(result));
    }

    public static List<Integer> test(int[] nums) {
        List<Integer> res = new ArrayList<>();
        Set<Integer> set =new HashSet<>();
        for(int i=0;i<nums.length;i++){
            set.add(nums[i]);
        }
        for(int i=1;i<=nums.length;i++){
            if(set.add(i)){
                res.add(i);
            }
        }
        return res;
    }


    public static List<Integer> test1(int[] nums) {
        int n = nums.length;
        for (int num:nums) {
            int x = (num -1) % n;
            nums[x] +=n;
        }
        List<Integer> res = new ArrayList<>();
        for(int i=0;i<n;i++){
            if(nums[i] <=  n){
                res.add(i+1);
            }
        }
        return res;
    }
}
